package com.example.demo.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.aliyun.oss.OSS;
import com.example.demo.configuration.AliyunOssConfig;
import com.example.demo.controller.bean.Result;
import com.example.demo.dto.CouponsRequestDTO;
import com.example.demo.dto.QuestionBankRequestDTO;
import com.example.demo.dto.QuestionRequestDTO;
import com.example.demo.mapper.entity.Question;
import com.example.demo.mapper.entity.QuestionBank;
import com.example.demo.service.QuestionBankManageService;
import com.example.demo.service.QuestionManageService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RequestMapping("questionManage")
@Api(value = "試題管理接口", tags = {"試題管理接口"})
@RestController
@Slf4j
public class QuestionManageController {
    @Autowired
    private QuestionManageService service;

    @ResponseBody
    @ApiOperation(value = "获取試題列表接口")
    @RequestMapping(value = "getQuestionList", method = {RequestMethod.POST})
    public Result<PageVo<Question>> getQuestionList(@RequestBody PageBo pageBo) {
        PageVo<Question> list = service.getQuestionList(pageBo);
        return Result.ok(list);
    }

    @ResponseBody
    @ApiOperation("題庫對應试题显示接口")
    @RequestMapping(value = "findQuestionBankList/{bankId}")
    public Result<PageVo<Question>> findQuestionBankList(@PathVariable("bankId")int bankId, @RequestBody PageBo pageBo) {
        PageVo<Question> list = service.findQuestionBankList(pageBo,bankId);
        return Result.ok(list);
    }
    @ResponseBody
    @ApiOperation(value = "搜索試題列表接口")
    @RequestMapping(value = "searchQuestion", method = {RequestMethod.POST})
    public Result<PageVo<QuestionRequestDTO>> getListSearch(@RequestBody QuestionRequestDTO request) {
        PageBo pageBo = new PageBo();
        pageBo.setPageNum(request.getPageNum());
        pageBo.setPageSize(request.getPageSize());

        List<Question> list = service.searchQuestionList(request);
        PageVo<QuestionRequestDTO> logs = new PageVo<>(pageBo,list);

        return Result.ok(logs);
    }

    @ApiOperation(value = "新增試題")
    @PostMapping("/addQuestion")
    public Result<String> uploadCommodity(@RequestBody Question request) {
        return service.addQuestion(request);
    }

    @ResponseBody
    @ApiOperation("移动到新题库接口")
    @RequestMapping(value = "moveQuestionBank", method = {RequestMethod.POST})
    public Result<String> moveQuestionBank(@RequestBody Question request) {
        return service.moveQuestionBank(request);
    }

    @ResponseBody
    @ApiOperation("修改試題接口")
    @RequestMapping(value = "updateQuestion", method = {RequestMethod.POST})
    public Result<String> updateQuestion(@RequestBody QuestionRequestDTO request) {
        return service.updateQuestion(request);
    }

    @ResponseBody
    @ApiOperation("删除接口")
    @RequestMapping(value = "deleteQuestion", method = {RequestMethod.POST})
    public Result<String> deleteQuestion(@RequestBody Question request) {
        return service.deleteQuestion(request);
    }

    @ResponseBody
    @ApiOperation("批量删除接口")
    @RequestMapping(value ="batchDeleteQuestion", method = {RequestMethod.POST})
    public Result<String> deleteList(@RequestBody List<Question> requestList) {
        return service.batchDeleteQuestion(requestList);
    }

}
